//
//  CADisplayLink+BCHelper.m
//  BCFoundation
//
//  Created by Basic on 2018/12/21.
//

#import "CADisplayLink+BCHelper.h"
#import <objc/runtime.h>

static char *bc_displayLinkHandleKey;

@interface CADisplayLink()
@end

@implementation CADisplayLink (BCHelper)
#pragma mark - system
+ (instancetype)bc_displayLinkWithBlock:(void(^)(CADisplayLink *displayLink) )block {
    CADisplayLink *displayLink = [[self class] displayLinkWithTarget:self selector:@selector(bc_displayLinkHandle:)];
    objc_setAssociatedObject(displayLink, &bc_displayLinkHandleKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
    return displayLink;
}

#pragma mark - private
/**
 刷新handle

 @param displayLink displayLink description
 */
+ (void)bc_displayLinkHandle:(CADisplayLink *)displayLink
{
    void(^actionBlock)(CADisplayLink *displayLink) = objc_getAssociatedObject(displayLink, &bc_displayLinkHandleKey);
    if (actionBlock) {
        actionBlock(displayLink);
    }
}


@end
